package com.dubbo.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.dubbo.service.ProviderService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:applicationContext.xml" })
public class Consumer {

	@Resource
	private ProviderService providerService;
	
	@Test
	public void test(){
		
		ExecutorService service = Executors.newFixedThreadPool(10);
		
		for(int i=0; i<100;i++){
			service.submit(new Runnable() {
				
				@Override
				public void run() {
					
					System.out.println(providerService.hello("李四"));
				}
			});
			
		}
		service.shutdown();
	}
	
	public static void main(String[] args) {
		ApplicationContext context = new FileSystemXmlApplicationContext(new String[] { "classpath*:applicationContext.xml" }); 
		final ProviderService pService = context.getBean(ProviderService.class);
		
		ExecutorService service = Executors.newFixedThreadPool(10);
		
		for(int i=0; i<10;i++){
			service.submit(new Runnable() {
				
				@Override
				public void run() {
					for(int i=0; i<10000;i++){
						System.out.println(pService.hello("李四"));
					}
					
				}
			});
			
		}
		service.shutdown();
	
	}
}
